package com.sogo;

import android.app.Activity;     
import android.os.Bundle;
import android.widget.Toast;
import android.database.Cursor;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.content.Intent;

public class RegistrationActivity extends Activity {
    /** Called when the activity is first created. */
	
	private EditText userName;
	private EditText firstName;
	private EditText lastName;
	private EditText Password;
	private EditText Email;
	private Button btnRegister;
	
	public String username;
	public String firstname;
	public String lastname;
	public String password;
	public String email;
	public int isEnter;
		
    @Override
    
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        

        final DBAdapter db = new DBAdapter(this);
        
        userName = (EditText)findViewById(R.id.userName);
        firstName = (EditText)findViewById(R.id.firstName);
        lastName = (EditText)findViewById(R.id.lastName);
        Password = (EditText)findViewById(R.id.password);
        Email = (EditText)findViewById(R.id.email);
        btnRegister = (Button)findViewById(R.id.register_button);
        
        btnRegister.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// Check Login
			    username = userName.getText().toString();
			    firstname = firstName.getText().toString();
				lastname = lastName.getText().toString();
				password = Password.getText().toString();
				email = Email.getText().toString();
				isEnter = 1;
				db.open();
		        long id = db.insertUser(username, firstname, lastname, email, password);
		        Cursor c = db.getUser();
		        if (c.moveToFirst())
		        {
		        	do{
		        		DisplayUser(c);
		       	}while (c.moveToNext());
		        }
		        db.close();
			}
			
        });		
      
        
        
       
    }
    
    public void DisplayUser(Cursor c){
		Toast.makeText(this,
				"id: " + c.getString(0) + "\n" + "UserName: " + c.getString(1) + "\n" + 
		 "First Name: " + c.getString(2) + "\n" + "Last Name: " + c.getString(3)
		 + "\n" + "Password: " + c.getString(4) + "\n" + "Email: " + c.getString(5), Toast.LENGTH_LONG).show();
	}
}